﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DIProject.Sales
{	public partial class Check : Form
	{	private DIProject.DataSets.Sales.ChecksRow checkRow;

		public Check() : this(null)
		{
		}

		public Check(DIProject.DataSets.Sales.ChecksRow checkRow)
		{	InitializeComponent();
			this.checkRow = checkRow;
		}

		private void Check_Load(object sender, EventArgs e)
		{	if(checkRow != null)
			{	try
				{	checkLinesTableAdapter.Fill(sales.CheckLines, checkRow.Id);
					Text = string.Format(Text, checkRow.CashRegisterName, checkRow.Casher, checkRow.DocNumber, checkRow.DocDate, checkRow.DocSum);
				}
				catch(SqlException eq)
				{	MessageBox.Show(this, string.Format("{0} ({1}): {2}", eq.Procedure, eq.LineNumber, eq.Message), Properties.Resources.strError, MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
				catch(Exception ex)
				{	MessageBox.Show(this, ex.Message, Properties.Resources.strError, MessageBoxButtons.OK, MessageBoxIcon.Error);
				}
			}
		}

		private void checkLinesGridView_KeyDown(object sender, KeyEventArgs e)
		{	if(e.KeyCode == Keys.Enter)
				e.Handled = true;
		}
	}
}